from selenium import webdriver
import time

try:
    driver = webdriver.Chrome()
    driver.get('https://www.baidu.com')

    driver.find_element_by_id('kw').send_keys('鸿蒙')
    driver.find_element_by_id('su').click()

    # 获取元素的文本
    driver.find_element_by_xpath('//*[]').text
    # 获取元素属性的值
    driver.find_element_by_xpath('//*[]').get_attribute('href')

except Exception as e:
    print(e)
finally:
    # 关闭当前窗口
    time.sleep(2)
    driver.close()